home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 14 / CU Amiga Magazine's Super CD-ROM 14 (1997)(EMAP Images)(GB)(Track 1 of 3)[!][issue 1997-09].iso / CUCD / Programming / XPK / Source / xpkmaster / libdata.a < prev    next >
Encoding:
Text File  |  1997-06-06  |  9.3 KB  |  346 lines

  1. * Routinesheader
  2. *
  3. *    Name:        libdata.a
  4. *    Main:        xpkmaster
  5. *    Versionstring:    $VER: libdata.a 4.14 (06.06.1997)
  6. *    Author:        SDI
  7. *    Distribution:    PD
  8. *    Description:    all the library startup data
  9. *
  10. * 3.10  28.10.96 : first real version
  11. * 3.11  25.11.95 : recompiled with SAS 6.57
  12. * 4.0   29.12.96 : added some new functions, OS2.0 only, corrected error in
  13. *    locale handling (Ooops - (A2) instead of A2 :-)
  14. * 4.1   11.01.97 : hopefully fixed buffer overworking bug
  15. * 4.2   30.01.97 : mem bug still was not completely fixed
  16. * 4.3   01.03.97 : changed semaphore structure
  17. * 4.4   09.03.97 : added preferences stuff
  18. * 4.5   23.03.97 : fixed Enforcer Hits
  19. * 4.6   28.03.97 : fixed prefs stuff
  20. * 4.7   31.03.97 : changed XpkQuery and Password stuff
  21. * 4.8   02.04.97 : changed a lot, removed some stuff
  22. * 4.9   03.04.97 : preferences buffers now via hookread and not direct
  23. * 4.10  04.04.97 : minor fixes
  24. * 4.11  10.04.97 : Password request now restores FirstScreen
  25. * 4.12  28.04.97 : fixed mem-corrupt bug and changed progress time calc
  26. * 4.13  11.05.97 : fixed reported errors in Expunge code
  27. * 4.14  06.06.97 : added DEBUG output
  28.  
  29.     NOLIST
  30.     INCLUDE    "AINCLUDE:IncDirs.i" *sets all includedirs, needed for my ASM
  31.     INCLUDE "exec/types.i"
  32.     INCLUDE "exec/initializers.i"
  33.     INCLUDE "exec/libraries.i"
  34.     INCLUDE "exec/lists.i"
  35.     INCLUDE "exec/alerts.i"
  36.     INCLUDE "exec/resident.i"
  37.     INCLUDE "dos/dos.i"
  38.     INCLUDE "libraries/locale.i"
  39.     INCLUDE    "lvo.i"
  40.     LIST
  41.  
  42. VERSION        EQU    4
  43. REVISION    EQU    14
  44. MINOSVERSION    EQU    37
  45.  
  46. STRINGANZ    EQU    10
  47. STRINGSTART    EQU    0
  48. ERRSTRINGANZ    EQU    34
  49. ERRSTRINGSTART    EQU    200
  50.  
  51. VSTRING    MACRO
  52.         DC.B    'xpkmaster 4.14 (06.06.97)',13,10,0
  53.     ENDM
  54.  
  55. ;    XDEF    InitTable
  56. ;    XDEF    Open
  57. ;    XDEF    Close
  58. ;    XDEF    Expunge
  59. ;    XDEF    Null
  60. ;    XDEF    LibName
  61.     XDEF    _DOSBase,_DosBase,_IntuitionBase,_UtilityBase,_XpkBase
  62.     XDEF    _MainVersion
  63.  
  64.     XREF    _LIBXpkExamine,_LIBXpkPack
  65.     XREF    _LIBXpkUnpack,_LIBXpkOpen,_LIBXpkRead,_LIBXpkWrite
  66.     XREF    _LIBXpkSeek,_LIBXpkClose,_LIBXpkQuery
  67.     XREF    _LIBXpkAllocObject,_LIBXpkFreeObject
  68.     XREF    _LIBXpkFault,_LIBXpkPrintFault
  69.     XREF    _LIBXpkPassRequest
  70.     XREF    _strings,_XpkErrs
  71.  
  72.     SECTION    "XPK_LibStart",Code
  73. Start    MOVEQ    #-1,d0    ; return an error in case someone
  74.     RTS        ; tried to run as a program
  75.  
  76. ; A romtag structure.  Both "exec" and "ramlib" look for this structure to
  77. ; discover magic constants about you (such as where to start running you
  78. ; from...).
  79.  
  80. RomTag        DC.W    RTC_MATCHWORD    ; UWORD rt_MatchWord
  81.         DC.L    RomTag        ; APTR  rt_MatchTag
  82.         DC.L    ENDCODE        ; APTR  rt_EndSkip
  83.         DC.B    RTF_AUTOINIT    ; UBYTE rt_Flags
  84. _MainVersion    DC.B    VERSION        ; UBYTE rt_Version
  85.         DC.B    NT_LIBRARY    ; UBYTE rt_type
  86.         DC.B    0        ; BYTE  rt_Pri
  87.         DC.L    LibName        ; APTR  rt_Name
  88.         DC.L    IDString    ; APTR  rt_IDString
  89.         DC.L    InitTable    ; APTR  rt_Init  table for InitResident()
  90.  
  91. LibName        DC.B    'xpkmaster.library',0
  92. DosName        DC.B    'dos.library',0
  93. INTUITIONNAME    DC.B    'intuition.library',0
  94. UTILITYNAME    DC.B    'utility.library',0
  95. LOCALENAME    DC.B    'locale.library',0
  96. CATALOGNAME    DC.B    'xpkmaster.catalog',0
  97.         CNOP    0,2
  98. IDString    VSTRING
  99.           CNOP    0,2    ; word alignement
  100.  
  101. ; The romtag specified that we were "RTF_AUTOINIT". This means that the
  102. ; rt_Init structure member points to one of these tables below. If the
  103. ; AUTOINIT bit was not set then RT_INIT would point to a routine to run.
  104.  
  105. InitTable:
  106.     DC.L    LIB_SIZE        ; size of library base data space
  107.     DC.L    funcTable        ; pointer to function initializers
  108.     DC.L    dataTable        ; pointer to data initializers
  109.     DC.L    initRoutine        ; routine to run
  110.  
  111. funcTable:
  112. ;------ standard system routines
  113.     DC.L    Open
  114.     DC.L    Close
  115.     DC.L    Expunge
  116.     DC.L    Null
  117. ;------ my libraries definitions
  118.     DC.L    Null
  119.     DC.L    _LIBXpkExamine
  120.     DC.L    _LIBXpkPack
  121.     DC.L    _LIBXpkUnpack
  122.     DC.L    _LIBXpkOpen
  123.     DC.L    _LIBXpkRead
  124.     DC.L    _LIBXpkWrite
  125.     DC.L    _LIBXpkSeek
  126.     DC.L    _LIBXpkClose
  127.     DC.L    _LIBXpkQuery
  128.     DC.L    _LIBXpkAllocObject
  129.     DC.L    _LIBXpkFreeObject
  130.     DC.L    _LIBXpkPrintFault
  131.     DC.L    _LIBXpkFault
  132.     DC.L    _LIBXpkPassRequest
  133. ;------ function table end marker
  134.     DC.L    -1
  135.  
  136. ; The data table initializes static data structures. The format is specified
  137. ; in exec/InitStruct routine's manual pages. The INITBYTE/INITWORD/INITLONG
  138. ; routines are in the file "exec/initializers.i". The first argument is the
  139. ; offset from the library base for this byte/word/long. The second argument
  140. ; is the value to put in that cell. The table is null terminated.
  141.  
  142. dataTable:
  143.     INITBYTE    LN_TYPE,NT_LIBRARY
  144.     INITLONG    LN_NAME,LibName
  145.     INITBYTE    LIB_FLAGS,LIBF_SUMUSED!LIBF_CHANGED
  146.     INITWORD    LIB_VERSION,VERSION
  147.     INITWORD    LIB_REVISION,REVISION
  148.     INITLONG    LIB_IDSTRING,IDString
  149.     DC.L        0
  150.  
  151. ; This routine gets called after the library has been allocated. The library
  152. ; pointer is in D0. The segment list is in A0. If it returns non-zero then
  153. ; the library will be linked into the library list.
  154.  
  155. initRoutine:
  156. ;------ get the library pointer into a convenient A register
  157.     MOVEM.L    A2/D6/D7/A6/A5,-(A7)
  158.     MOVEA.L    D0,A5
  159.     MOVE.L    D0,_XpkBase        ; init XpkBase for internal calls
  160. ;------ save a pointer to our loaded code
  161.     MOVE.L    A0,SegList
  162. ;
  163. ; specific openings here
  164. ;
  165.     MOVEA.L    4.W,A6
  166.     MOVEQ    #MINOSVERSION,D0
  167.     LEA    DosName(PC),A1
  168.     JSR    _LVOOpenLibrary(A6)
  169.     MOVE.L    D0,_DOSBase
  170.     BEQ.W    .kill
  171.     MOVEQ    #MINOSVERSION,D0
  172.     LEA    INTUITIONNAME(PC),A1
  173.     JSR    _LVOOpenLibrary(A6)
  174.     MOVE.L    D0,_IntuitionBase
  175.     BEQ.B    .kill
  176.     MOVEQ    #MINOSVERSION,D0
  177.     LEA    UTILITYNAME(PC),A1
  178.     JSR    _LVOOpenLibrary(A6)
  179.     MOVE.L    D0,_UtilityBase
  180.     BEQ.B    .kill
  181.     MOVEQ    #38,D0
  182.     LEA    LOCALENAME(PC),A1
  183.     JSR    _LVOOpenLibrary(A6)
  184.     MOVE.L    D0,_LocaleBase
  185.     BEQ.B    .endok
  186.     MOVEA.L    D0,A6
  187.     SUBA.L    A0,A0
  188.     JSR    _LVOOpenLocale(A6)
  189.     MOVE.L    D0,_Locale
  190.     BEQ.B    .endok
  191.     MOVEA.L    D0,A0
  192.     LEA    CATALOGNAME(PC),A1
  193.     LEA    CATALOGTAGS(PC),A2
  194.     JSR    _LVOOpenCatalogA(A6)
  195.     MOVE.L    D0,_Catalog
  196.     BEQ.B    .endok
  197.     MOVEQ    #STRINGANZ-1,D6
  198.     MOVEQ    #STRINGSTART,D7
  199.     LEA    _strings,A2
  200.     BSR.B    DoLocale
  201.     MOVEQ    #ERRSTRINGANZ-1,D6
  202.     MOVE.L    #ERRSTRINGSTART,D7
  203.     LEA    _XpkErrs,A2
  204.     BSR.B    DoLocale
  205.  
  206. .endok    MOVE.L    A5,D0
  207. .end    MOVEM.L    (A7)+,A2/D6/D7/A6/A5
  208.     RTS
  209. .kill    BSR.W    KillLibs
  210.     MOVEQ    #0,D0
  211.     BRA.B    .end
  212.  
  213. DoLocale    MOVE.L    _Catalog(PC),A0
  214.         MOVE.L    D7,D0
  215.         MOVEA.L    (A2),A1
  216.         ADDQ.L    #1,D7
  217.         JSR    _LVOGetCatalogStr(A6)
  218.         MOVE.L    D0,(A2)+
  219.         DBRA    D6,DoLocale
  220.         RTS
  221.  
  222. ; here begins the system interface commands. When the user calls
  223. ; OpenLibrary/CloseLibrary/RemoveLibrary, this eventually gets translated
  224. ; into a call to the following routines (Open/Close/Expunge). Exec has
  225. ; already put our library pointer in A6 for us. Exec has turned off task
  226. ; switching while in these routines (via Forbid/Permit), so we should not
  227. ; take too long in them.
  228.  
  229. ; Open returns the library pointer in D0 if the open was successful. If the
  230. ; open failed then null is returned. It might fail if we allocated memory
  231. ; on each open, or if only one application could have the library open at
  232. ; a time...
  233.  
  234. Open:        ; (libptr:A6, version:D0)
  235. ;------ mark us as having another opener
  236.     ADDQ.W    #1,LIB_OPENCNT(A6)
  237.     BCLR    #LIBB_DELEXP,LIB_FLAGS(A6)
  238.     MOVE.L    A6,D0
  239.     RTS
  240.  
  241. ; There are two different things that might be returned from the Close
  242. ; routine. If the library is no longer open and there is a delayed expunge
  243. ; then Close should return the segment list (as given to Init). Otherwise
  244. ; close should return NULL.
  245.  
  246. Close:        ; (libptr:A6)
  247. ;------ set the return value
  248.     MOVEQ    #0,D0
  249. ;------ mark us as having one fewer openers
  250.     SUBQ.W   #1,LIB_OPENCNT(A6)
  251. ;------ see if there is anyone left with us open
  252.     BNE.B    .OneLeft
  253. ;------ do the expunge
  254.     BTST    #LIBB_DELEXP,LIB_FLAGS(A6)
  255.     BEQ.B    .OneLeft
  256.     BSR.B    Expunge
  257. .OneLeft
  258.     RTS
  259.  
  260. ; There are two different things that might be returned from the Expunge
  261. ; routine. If the library is no longer open then Expunge should return the
  262. ; segment list (as given to Init). Otherwise Expunge should set the delayed
  263. ; expunge flag and return NULL.
  264. ; One other important note: because Expunge is called from the memory
  265. ; allocator, it may NEVER Wait() or otherwise take long time to complete.
  266.  
  267. Expunge:    ; (libptr: A6)
  268.     MOVEM.L    D2/A5/A6,-(A7)
  269.     MOVEA.L    A6,A5
  270.     MOVEA.L    4.W,A6
  271. ;------ see if anyone has us open
  272.     TST.W    LIB_OPENCNT(A5)
  273.     BEQ.B    .DoIt
  274.     BSET    #LIBB_DELEXP,LIB_FLAGS(A5)
  275.     MOVEQ    #0,D0
  276.     BRA.B    .Expunge_End
  277. .DoIt
  278. ;------ go ahead and get rid of us.  Store our seglist in D2
  279.     MOVE.L    SegList(PC),D2
  280. ;------ unlink from library list
  281.     MOVEA.L    A5,A1
  282.     JSR    _LVORemove(A6)
  283. ;
  284. ; device specific closings here...
  285.     BSR.B    KillLibs
  286. ;
  287. ;------ free our memory
  288.     MOVEQ    #0,D0
  289.     MOVEA.L    A5,A1
  290.     MOVE.W    LIB_NEGSIZE(A5),D0
  291.     SUBA.L    D0,A1
  292.     ADD.W    LIB_POSSIZE(A5),D0
  293.     MOVEA.L    4.W,A6
  294.     JSR    _LVOFreeMem(A6)
  295. ;------ set up our return value
  296.     MOVE.L    D2,D0
  297.  
  298. .Expunge_End
  299.     MOVEM.L    (A7)+,D2/A5/A6
  300.     RTS
  301.  
  302. KillLibs:    MOVEA.L    4.W,A6
  303.         MOVEA.L    _IntuitionBase(PC),A1
  304.         MOVE.L    A1,D0                ; for checking
  305.         BEQ.B    .utility
  306.         JSR    _LVOCloseLibrary(A6)
  307. .utility    MOVEA.L    _UtilityBase(PC),A1
  308.         MOVE.L    A1,D0
  309.         BEQ.B    .dos
  310.         JSR    _LVOCloseLibrary(A6)
  311. .dos        MOVEA.L    _DOSBase(PC),A1
  312.         MOVE.L    A1,D0
  313.         BEQ.B    .locale
  314.         JSR    _LVOCloseLibrary(A6)
  315. .locale        MOVEA.L    _LocaleBase(PC),A6
  316.         MOVE.L    A6,D0
  317.         BEQ.B    .endlibs
  318.         MOVEA.L    _Catalog(PC),A0
  319.         MOVE.L    A0,D0
  320.         BEQ.B    .closelocale
  321.         JSR    _LVOCloseCatalog(A6)
  322. .closelocale    MOVEA.L    _Locale(PC),A0
  323.         MOVE.L    A0,D0
  324.         BEQ.B    .closelibrary
  325.         JSR    _LVOCloseLocale(A6)
  326. .closelibrary    MOVEA.L    A6,A1
  327.         MOVEA.L    4.W,A6
  328.         JSR    _LVOCloseLibrary(A6)
  329. .endlibs    RTS
  330.  
  331. Null:    MOVEQ    #0,D0
  332.     RTS
  333.  
  334. CATALOGTAGS:    DC.L    OC_Version,2,TAG_DONE
  335. SegList:    DC.L    0    * set by Init
  336. _Catalog:    DC.L    0    * access only by Init
  337. _Locale:    DC.L    0    * or by Expunge, no need to access
  338. _LocaleBase:    DC.L    0    * locale in program
  339. _DosBase:
  340. _DOSBase:    DC.L    0    * set by Init    these are library globals
  341. _UtilityBase:    DC.L    0    * set by Init    in C Code read only !!!
  342. _XpkBase:    DC.L    0    * set by Init
  343. ENDCODE:
  344. _IntuitionBase:    DC.L    0    * set by Init
  345.         END
  346.